function ...
[softData, HARQ] = WiSiL_Rx_chaseCombining( softData, encoder, paramHARQ, ...
                                            HARQ )
% WISIL_RX_CHASECOMBINING Implement HARQ packet combining
%
%   [SOFTDATA, HARQ] = WiSiL_Rx_chaseCombining ( SOFTDATA, ENCODER,
%    PARAMHARQ, HARQ ) combines different versions of a received packet
%   available in SOFTDATA, which is correspondly updated. 
%   ENCODER is a struct containing the code parameters, PARAMHARQ is a
%   struct containing the Hybrid ARQ parameters, and HARQ contains current
%   Hybrid ARQ information, which is updated by the function.

% History
%   ?????

if (paramHARQ.enable)
    if (strcmpi(HARQ.combination,{'CC'}) == 1 )


        numBlocks = encoder.blocks.numBlocks;
        C1 = encoder.blocks.C1;
        C2 = encoder.blocks.C2;
        K1 = encoder.blocks.K1;
        K2 = encoder.blocks.K2;
        fillerBits = encoder.blocks.fillerBits;
        constraint = encoder.TurboCoding.constraint;
        R = encoder.TurboCoding.R;
        sizeCrc = length(encoder.crc.polyB);
        temp = 0;

        for aux = 1:C2
            if aux == 1
                symbolCounter{aux,1} = temp + 1: temp + ...
                                                 ( K2 + constraint - ...
                                                   fillerBits )/R;
                temp = temp+(K2+constraint - fillerBits)/R;
            elseif aux ==C1+C2
                symbolCounter{aux,1} = temp+1:temp+(K2+constraint )/R;
                temp = temp+(K2+constraint - (sizeCrc -1))/R;
            else
                symbolCounter{aux,1} = temp+1:temp+(K2+constraint)/R;
                temp = temp+(K2+constraint)/R;
            end
        end

        for aux = C2+1:C1+C2
            if aux == 1
                symbolCounter{aux,1} = temp + 1 : temp + ...
                                                  ( K1 + constraint - ...
                                                    fillerBits )/R;
                temp = temp+(K1+constraint - fillerBits)/R;
            elseif aux == C1+C2
                symbolCounter{aux,1} = temp+1:temp+(K1+constraint)/R;
                temp = temp+(K1+constraint - (sizeCrc -1))/R;
            else
                symbolCounter{aux,1} = temp+1:temp+(K1+constraint)/R;
                temp = temp+(K1+constraint)/R;
            end
        end

        for block = 1:numBlocks

            if(HARQ.repetitions(block) > 1)
                softData(symbolCounter{block,1},1) = ...
                    softData(symbolCounter{block,1},1) + ...
                    HARQ.soft_data_buffer(symbolCounter{block,1});
            end
        end

    end

end
HARQ.softDataBuffer = softData;
return